﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.IO;
using Common;

public partial class admin_finance_reportoverview : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        PageBegin("finance", 1);

        switch (RequestBase.GetFormString("otype"))
        {
            case "loaddata":
                LoadingData();
                break; 
        }
    }

    #region 信息绑定
    void LoadingData()
    {
        try
        {
            string ctrl = "~/admin/finance/_controls/ctlFinanceRecord.ascx";

            Control uc_rep = LoadControl(ctrl);

            Repeater rptReportList = (Repeater)uc_rep.FindControl("rptReportList");

            DataTable dat = BLL.Search.CommonSearch.ExecSelect("FinanceReportBase",
             new string[] { "[Year]" },
             new string[] { "Equal" },
             new string[] { "2011" },
             new string[] { "[Month]" },
             new string[] { "ASC" });

            rptReportList.DataSource = dat;
            rptReportList.DataBind();

            decimal a = 0, b = 0, c = 0;
            foreach (DataRow dr in dat.Select())
            {
                a += decimal.Parse(dr["TotalIncome"].ToString());
                b += decimal.Parse(dr["TotalOutlay"].ToString());
                c += decimal.Parse(dr["TotalProfit"].ToString());
            }

            uc_rep.GetType().GetProperty("TotalIncome").SetValue(uc_rep, a.ToString(), null);
            uc_rep.GetType().GetProperty("TotalOutlay").SetValue(uc_rep, b.ToString(), null);
            uc_rep.GetType().GetProperty("TotalProfit").SetValue(uc_rep, c.ToString(), null);

            StringBuilder strb = new StringBuilder();
            StringWriter sw = new StringWriter(strb);
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            rptReportList.RenderControl(htw);

            BLL.AjaxHelper.ResponseWrite(strb.ToString());
        }
        catch (System.Threading.ThreadAbortException err)
        {
            //nothing   to   do   
        }
        catch (Exception err)
        {
            BLL.AjaxHelper.ResponseWrite(err.Message);
        }
    }
    #endregion
}
